/*
 * @Author: C.
 * @Date: 2023-11-30 09:00:34
 */
import type { DaDropdownMenuListItem } from '../../../filter/typing'
const defaultPreFilters: DaDropdownMenuListItem[] = [
  {
    title: '搜索',
    type: 'search',
    prop: 'Keyword',
  },
  {
    title: '排序',
    type: 'sort',
    prop: 'SortOrder',
    value: 1, // 默认升序
  },
  {
    title: '日期',
    type: 'daterange',
    prop: 'DateRange',
  },
]
const defaultAftFilters: DaDropdownMenuListItem[] = [
  {
    title: '筛选',
    type: 'slot1',
    prop: 'slot1',
  },
]

function cpnAdapter(schemas: any[]): DaDropdownMenuListItem[] {
  return schemas
    .filter(
      (item) =>
        item.component == 'Checkbox' ||
        item.component == 'Select' ||
        item.component == 'Radio'
    )
    .map((item) => {
      return {
        title: item.label,
        prop: item.field,
        type: 'cell',
        showAll: true,
        showIcon: true,
        options: item?.componentProps?.options ?? [],
        value: item.defaultValue,
      } as DaDropdownMenuListItem
    })
}
// | "EasyInput"
// | "Checkbox"
// | "Select"
// | "UniDatetimePicker"
// | "UniDataPicker"
// | "mstSlider"
// | "mstSwitch"
// | "mstTextArea"
// | "mstUploadImg"
// | "multipleSelect"
export function form2Filter(
  schema: any[] | (() => any[])
): DaDropdownMenuListItem[] {
  const getSchema = Array.isArray(schema) ? schema : schema()
  return [...defaultPreFilters, ...cpnAdapter(getSchema), ...defaultAftFilters]
}
